import matplotlib.pyplot as plt
import numpy as np
import os

'''
    第1张图画1-3阶基，第2张图画3-6阶基
'''

def plotAirfoilGeom(x, y_list, labels, save_path):
    '''
        在同一张图上展示一系列翼型
    :param coordinates:
    :param file_path:
    :return:
    '''

    # plt.rc('font', family='Latin Modern Roman')
    plt.rc('font', family='Times New Roman')

    linestyle_list = ['solid',
                      ':', '--', '-.',
                      ':', '--', '-.']
    color_list = ["black", "red", "blue", "red", "blue", "red", "blue"]
    long = 7
    height = 6.6

    fig = plt.figure(figsize=(long, height), dpi=80)
    fig.canvas.draw()

    for i in range(y_list.shape[1]):
        plt.plot(x, y_list[:, i],
                 linewidth=1,
                 linestyle=linestyle_list[i],
                 label=labels[i],
                 c=color_list[i])

    font = {'weight': 'normal',
            'size': 16}

    # 横纵坐标标题
    plt.xlabel("X/C", font)
    plt.ylabel("Y/C", font)

    font1 = 13
    # 横纵坐标刻度
    plt.xticks(size=font1)
    plt.yticks(size=font1)

    # plt.xlim((-0.01, 1.01))
    # plt.ylim((-0.07, 0.07))
    plt.legend(fontsize=font1) #, bbox_to_anchor=(0.63, 0.43))
    plt.grid()

    plt.savefig(save_path, dpi=1000, bbox_inches='tight')
    plt.close()


if __name__ == "__main__":

    x = np.loadtxt("basis_data/x.dat", delimiter=' ')[:, 0]

    y = np.loadtxt("basis_data/POD_basis.csv", delimiter=',')[:, 0:3]
    save_path = r"basis_data/basis_1_3_not_metric.png"
    labels = ["$1^{st}$ Basis", "$2^{nd}$ Basis", "$3^{rd}$ Basis"]
    plotAirfoilGeom(x, y, labels, save_path)
    print("二维翼型可视化图已保存在{}".format(save_path))


    y = np.loadtxt("basis_data/POD_basis.csv", delimiter=',')[:, 3:6]
    save_path = r"basis_data/basis_4_6_not_metric.png"
    labels = ["$4^{th}$ Basis", "$5^{th}$ Basis", "$6^{th}$ Basis"]
    plotAirfoilGeom(x, y, labels, save_path)
    print("二维翼型可视化图已保存在{}".format(save_path))
